package com.credit.jumu.playcard.view;

import android.content.Context;
import android.support.v4.widget.SwipeRefreshLayout;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.ViewConfiguration;

/**
 * Created by Administrator on 2017/10/27/027.
 */

public class MySwipeRefreshLayout extends SwipeRefreshLayout {
	private float mInitialDownY;
	private int mTouchSlop;

	public MySwipeRefreshLayout(Context context) {
		this(context, null);
	}

	public MySwipeRefreshLayout(Context context, AttributeSet attrs) {
		super(context, attrs);
		mTouchSlop = ViewConfiguration.get(context).getScaledTouchSlop();
	}

	@Override
	public boolean onInterceptTouchEvent(MotionEvent ev) {

		final int action = ev.getAction();
		switch (action) {
			case MotionEvent.ACTION_DOWN:
				mInitialDownY = ev.getY();
				break;
			case MotionEvent.ACTION_MOVE:
				final float yDiff = ev.getY() - mInitialDownY;
				if (yDiff < mTouchSlop) {
					return false;
				}
		}
		return super.onInterceptTouchEvent(ev);
	}


	/**
	 * @return 返回灵敏度数值
	 */
	public int getTouchSlop() {
		return mTouchSlop;
	}

	/**
	 * 设置下拉灵敏度
	 *
	 * @param mTouchSlop dip值
	 */
	public void setTouchSlop(int mTouchSlop) {
		this.mTouchSlop = mTouchSlop;
	}
}

